<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<html>
<head>
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
</head>
<style>

</style>
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<body class="no-skin">
<div class="main-container" id="main-container">
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <%--   功能按钮 --%>
                <div class="row">
                    <div class="col-xs-12">
                            搜索:<input type="text" name="seach" style="vertical-align: bottom">
                            <button class="btn btn-success btn-sm categoryConfirm"
                                    onclick="confirmBtn(this,'seach','/common/releaseBriefing/briefCategory/')">确定</button>
                            <button class="btn btn-sm btn-default hidden" id="edit">编辑</button>
                            <button class="btn btn-sm btn-success" id="create">新增攻坚简报</button>
                            <button class="btn btn-sm btn-success " id="weekly">周文档</button>
                            <button class="btn btn-sm btn-success" id="briefCategory">事项类型管理</button>
                            <button class="btn btn-sm btn-danger hidden" id="delete">删除</button>
                        </div>
                    </div>
                </div>
                <%--   数据表格         --%>
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <!-- jqGrid表格 -->
                            <table id="gridTable"></table>
                            <!-- jqGrid工具类 -->
                            <div id="gridPager"></div>
                            <!-- 查询对话框 -->
                            <div style="display: none;">
                                <div class="row" id="queryDialog"></div>
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                    <h3 class="text-center">周文档</h3>
                   <div class="row">
                <div class="col-xs-12">
                    <!-- PAGE CONTENT BEGINS -->
                    <!-- jqGrid表格 -->
                    <table id="gridTable1"></table>
                    <!-- jqGrid工具类 -->
                    <div id="gridPager1"></div>
                    <!-- 查询对话框 -->
                    <div style="display: none;">
                        <%--<div class="row" id="queryDialog"></div>--%>
                    </div>
                    <!-- PAGE CONTENT ENDS -->
                </div><!-- /.col -->
            </div><!-- /.row -->
                </div>
            </div>
        </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>
<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/common/releaseBriefing"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    // var colNames = ['', '事项类型', '标题','创建时间','周期', '摘要', '附件','状态','操作'];
    var colNames = ['','标题','创建时间','周期', '摘要', '附件','附件名字','状态','操作'];

    //周文档
    var colNames1 = ['','标题','创建时间','周期', '附件','附件名字','状态','操作'];
    var colNames1 = ['','标题','创建时间','周期', '附件','附件名字','状态','操作'];

    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'title', index: 'title', width: 250, editable: true},
        {name: 'dateAttr', index: 'dateAttr', width: 250, editable: true,key: true},
        {name: 'period', index: 'period', width: 250, editable: true,formatter: periodFormatter},
        {name: 'summary', index: 'summary', width: 250, editable: true},
        {name: 'annex', index: 'annex', width: 150,align : "center", editable: true,formatter: fileFormatter},
        {name: 'annexName', index: 'annexName', width: 250, editable: true},
        {name: 'status', index: 'status', width: 160, editable: true,formatter:statusFormatter},
        {name : 'caozuo', width : 200, align : "center",formatter: showDetailFormatter }
    ];

    //周文档
    var colModel1 = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'title', index: 'title', width: 250, editable: true},
        {name: 'datetime', index: 'dateAttr', width: 250, editable: true,key: true},
        {name: 'period', index: 'period', width: 250, editable: true,formatter: periodFormatter},
        {name: 'weekDoc', index: 'annex', width: 150,align : "center", editable: true,formatter: fileFormatter},
        {name: 'weekDocName', index: 'annexName', width: 250, editable: true},
        {name: 'state', index: 'state', width: 160, editable: true,formatter:statusFormatter2},
        {name : 'caozuo', width : 200, align : "center",formatter: showDetailFormatter2 }
    ];


    /**
     * 状态   格式化
     * 0 待上架  1 已上架  2 下架
     */
    function statusFormatter(data) {
        switch(data) {
            case '1':
                return '已上架';
                break;
            case '2':
                return '已下架';
            default:
                return '待上架';
        }
    }

    /**
     * 状态   格式化
     * 0 待上架  1 已上架  2 下架
     */
    function statusFormatter2(data) {
        switch(data) {
            case '1':
                return '已上架';
                break;
            case '0':
                return '已下架';
            default:
                return '待上架';
        }
    }

    /**
     * periodFormatter
     */
    function periodFormatter(data) {
        return "第" + data + "期"
    }


    /**
     * 附件格式化
     */
    var gJFileName = "";
    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return "<span class='downDetailGJ' FileSysId = '"+ data +"' style='width: 40px;cursor: pointer;color: #049CE6;' title='下载'>下载</span>"
        }
    }
    //下载按钮
    $(document).on("click",".downDetailGJ",function () {
       download(this);
    })

    //下载按钮
    function downDetail(id) {
        var url = "/filesUpload/download/" + id;
        window.open(url);
    }

    function showDetailFormatter2(value, grid, rows, state) {
        //console.log(value, grid, rows, state);
        grid.colModel.title=false
        var html = "";
        if(rows.sysId != undefined && rows.state != undefined) {
            html+="<div style='color: #049CE6;display: flex;justify-content: center'>"
            if( rows.state == '0') {
                html += "<div style='width: 40px;cursor: pointer' title='上架' data-status='1' data-id='"+rows.sysId +"' onclick='updateStatus2(this)'>上架</div>"
            } else {
                html += "<div style='width: 40px;cursor: pointer' title='下架' data-status='0' data-id='"+rows.sysId +"' onclick='updateStatus2(this)'>下架</div>"
            }
            // html += "<div style='width: 40px;cursor: pointer;' title='查看' data-id='"+rows.sysId +"' onclick='showView(this)'>查看</div>"
        } else {
            // html += "<div style='width: 40px;cursor: pointer;margin: 0 auto' title='查看' data-id='"+rows.sysId +"' onclick='showView(this)'>查看</div>"
        }
        html += "</div>"
        return html;
    }

    function showDetailFormatter(value, grid, rows, state) {
        //console.log(value, grid, rows, state);
        grid.colModel.title=false
        var html = "";
        if(rows.sysId != undefined && rows.status != undefined) {
            html+="<div style='color: #049CE6;display: flex;justify-content: center'>"
            if( rows.status == '1') {
                html += "<div style='width: 40px;cursor: pointer' title='下架' data-status='2' data-id='"+rows.sysId +"' onclick='updateStatus(this)'>下架</div>"
            } else {
                html += "<div style='width: 40px;cursor: pointer' title='上架' data-status='1' data-id='"+rows.sysId +"' onclick='updateStatus(this)'>上架</div>"
            }
            // html += "<div style='width: 40px;cursor: pointer;' title='查看' data-id='"+rows.sysId +"' onclick='showView(this)'>查看</div>"
        } else {
            // html += "<div style='width: 40px;cursor: pointer;margin: 0 auto' title='查看' data-id='"+rows.sysId +"' onclick='showView(this)'>查看</div>"
        }
        html += "</div>"
        return html;
    }

    /**
     * 模板类型   格式化
     * 1短信 2邮件 3微信
     */
    function templateTypeFormatter(data) {
        switch(data) {
            case '1':
                return '短信模板';
                break;
            case '2':
                return '邮件模板';
                break;
            case '3':
                return '微信模板';
            default:
                return '-';
        }
    }
    var rowIds,rowids=[];
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }
    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }
    //jqgrid的具体执行方法
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        autoScroll: false,
        shrinkToFit: true,
        multiselect:false,
        rownumbers: true,
        sortable:true,
        sortorder:'desc',
        sortname:"dateAttr",
        onSelectRow: function (rowid, status) {
            //暂时没有附件名字     滞后++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            // gJFileName = $('#gridPager').jqGrid('getRowData',rowid).gJFileName;
            rowIds = rowid
            // var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
        },
    });
    jqgrid({
        gridTableId: "#gridTable1",
        gridPagerId: "#gridPager1",
        colNames:colNames1,
        colModel:colModel1,
        url:"/common/releaseBriefing/queryWeekDoc/",
        autoScroll: false,
        shrinkToFit: true,
        multiselect:false,
        rownumbers: true,
        onSelectRow: function (rowid, status) {
            //暂时没有附件名字     滞后++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            // gJFileName = $('#gridPager').jqGrid('getRowData',rowid).gJFileName;
            rowIds = rowid
            // var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
        },
    });
    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));
    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        showDialog({
            dialogTitle: '条件搜索',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询简报</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });


    //更新操作
    $("#edit").click(function () {
        showEditView();
    });
    //显示编辑对话框
    function showEditView() {
        showEditDialog({
            tableId: "#gridTable",
            dialogTitle: "更新对话框",
            dialogUrl: getUrl("edit"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="edit()" id="updatebtn" >更新简报</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            errorTitle: "消息对话框",
            errorMutiSelectMessage: '您当前选中多行，请重新选择',
            errorUnSelectMessage: '您当前尚未选中一行，请选择后再试',
            errorOk: '确定'
        });
    }

    //删除
    $("#delete").click(function () {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function () {
        parent.openapp("/common/releaseBriefing/create", "releaseBriefingAdd", "创建简报")
    });


    $("#weekly").click(function () {
        loadDialog({
            dialogTitle: "周文档",
            dialogUrl: getUrl("weekcreate"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()" id="create-template-btn">创建简报</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });
    // 周文档保存数据
    function create() {
        $("input[name=weekDoc]").val()
        if (!$("input[name=weekDoc]").val()) {
            return alert("请选择附件")
        }
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("weekcreate"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //briefCategory 事项类型管理
    $("#briefCategory").click(function () {
        parent.openapp("/common/releaseBriefing/briefCategory","administration","事项类型管理");
    })


    $("#gridTable").dblclick(function (e) {
       // showView();
    });


    function updateStatus($this) {
        var status = $($this).data('status')
        var sysId = $($this).data('id')
         var data = {'sysId':sysId,"status":status}
        $.post('/common/releaseBriefing/updateStatus',data,function (res) {
            if(res){
                if(res.code != undefined && res.code == '200') {
                    alert('变更成功')
                    reload("#gridTable")
                } else {
                    alert('变更失败')
                }
            } else {
                alert('系统错误，请稍后重试！')
            }
        })
    }

    //周文档
    function updateStatus2($this) {
        var status = $($this).data('status')
        var sysId = $($this).data('id')
        var data = {'id':sysId,"state":status}
        $.get('/common/releaseBriefing/updateWeekState',data,function (res) {
            if(res){
                if(res.code != undefined && res.code == '200') {
                    alert('变更成功')
                    reload("#gridTable1")
                } else {
                    alert('变更失败')
                }
            } else {
                alert('系统错误，请稍后重试！')
            }
        })
    }

    function showView($this) {
        var sysId = $($this).data('id')
        console.log("查看："+sysId)
    }
    function rightTipBOX(msg) {
        if(msg == undefined){
            msg = ''
        }
        $.gritter.add({
            title: "提示",
            text: msg
        });
    }
</script>
</body>
</html>
